package day13.CollectionTask;

import java.util.*;

public class TaskSeven {
    public static void main(String[] args) {
        Map<String, List<String>> productInfo = new HashMap<>();
        addProduct(productInfo,"手机", "Smartphone");
        addProduct(productInfo, "手机", "Laptop");
        addProduct(productInfo, "衣服", "T-Shirt");
        addProduct(productInfo, "衣服", "Jeans");
        Set<Map.Entry<String, List<String>>> entries = productInfo.entrySet();
        for (Map.Entry<String, List<String>> entry : entries) {
            String category = entry.getKey();
            List<String> products = entry.getValue();
            System.out.println("商品类别: " + category);
            for (String product : products) {
                System.out.println("- " + product);
            }
        }
    }

    public static void addProduct(Map<String, List<String>> productInfo, String category, String product){
        if (productInfo.containsKey(category)) {
            productInfo.get(category).add(product);
        } else {
            List<String> productList = new ArrayList<>();
            productList.add(product);
            productInfo.put(category, productList);
        }
    }
}
